package com.myself.cloud.service.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.myself.cloud.api.IMyselfUserService;
import com.myself.cloud.entity.ResultEntity;
import com.myself.cloud.entity.bean.MyselfUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 *  前端控制器
 * @author baijialiang
 * @since 2022-09-01
 */

@RestController
@Api(value ="", tags ="")
@RequestMapping("/myself-user")
public class MyselfUserController {
    @Autowired
    private IMyselfUserService myselfUserService;

    @PostMapping("/list")
    @ApiOperation(value = "列表查询",notes = "list")
    public ResultEntity<List<MyselfUser>> list(@RequestBody MyselfUser myselfUser){
        QueryWrapper<MyselfUser> queryWrapper= new QueryWrapper<>(myselfUser);
        // 自己补写条件
        return ResultEntity.success(myselfUserService.list(queryWrapper));
    }

    @PostMapping("/pageList")
    @ApiOperation(value = "列表分页查询，pageSize、pageNum从请求头中获取",notes = "pageList")
    public ResultEntity<Page<MyselfUser>> pageList(@RequestBody MyselfUser myselfUser, @RequestHeader Integer pageSize, @RequestHeader Integer pageNum){
        QueryWrapper<MyselfUser> queryWrapper= new QueryWrapper<>(myselfUser);
        // 自己补写条件
        Page<MyselfUser> page = new Page<>(pageNum, pageSize);
        return ResultEntity.success(myselfUserService.page(page, queryWrapper));
    }

    @PostMapping("/detail")
    @ApiOperation(value = "查看详情",notes = "MyselfUser")
    public ResultEntity<MyselfUser> getMyselfUserById(@RequestBody MyselfUser myselfUser){
        return ResultEntity.success(myselfUserService.getById(myselfUser));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增",notes = "MyselfUser")
    public ResultEntity<Boolean> saveMyselfUser(@RequestBody MyselfUser myselfUser){
        if(myselfUserService.save(myselfUser)){
            return ResultEntity.success();
        }
        return ResultEntity.error("");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改",notes = "MyselfUser")
    public ResultEntity<Boolean> update(@RequestBody MyselfUser myselfUser){
        if(myselfUserService.updateById(myselfUser)){
            return ResultEntity.success();
        }
        return ResultEntity.error("");
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除",notes = "MyselfUser")
    public ResultEntity<Boolean> remove(@RequestBody MyselfUser myselfUser){
        if(myselfUserService.removeById(myselfUser)){
            return ResultEntity.success();
        }
        return ResultEntity.error("");
    }
}
